package com.example.internet.service;

public class BytesUtils {
    /**
     * 获取 bytes 有效⻓度
     *
     * @param bytes
     * @return
     */
    public static int getValidLength(byte[] bytes) {
        int i = 0;
        if (null == bytes || 0 == bytes.length)
            return i;
        for (; i < bytes.length; i++) {
            if (bytes[i] == '\0')
                break;
        }
        return i;
    }

    /**
     * 截取 bytes
     *
     * @param b
     * @param off
     * @param length
     * @return
     */
    public static byte[] subByte(byte[] b, int off, int length) {
        byte[] b1 = new byte[length];
        System.arraycopy(b, off, b1, 0, length);
        return b1;
    }
}

